$ ->

  $wrap = $(".search_wrap")
  $wrap.on "change", "select.category_id", ->
    category_id = $(@).val()

    if parseInt(category_id) > 0
      $.ajax
        url: "/categories/#{category_id}/childrens"
        dataType: 'json'
        success: (data) ->
          
          options = "<option>请选择</option>"

          for item in data
            options += "<option value='#{item.id}'>#{item.cataname}</option>"

          $("select.children_id", $wrap).html(options)
          $("select.children_id", $wrap).show();

        error: (xhr) ->
          console.error(xhr.responseText)
    else
      $("select.children_id", $wrap).hide()


  # $wrap.on "focus", ".keywords", ->
  #   $(@).val('')

  # $wrap.on "blur", ".keywords", ->
  #   if $(@).val() == ""
  #     $(@).val("关键词")
    
  $("input.begin_time", $wrap).datepicker(format: 'yyyy-mm-dd')
  $("input.end_time", $wrap).datepicker(format: 'yyyy-mm-dd')

  $form = $("form.research")
  $form.on "click", ".submit", ->
    if $.trim($("input.keywords", $form).val()) isnt ""
      $form.submit()
  
  
  ###
  $form = $("form.research")
  $('.search_btn').on 'click', ->
    $content = $('#searchContent')
    if $content.css('visibility')=='visible' && $.trim($("input", $content).val()) isnt ""
      $form.submit();
    else
      $content.css('visibility','visible');    
  ###